package com.zykj.thread.traditional;

import sun.applet.Main;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * @author zhoulj(周利军) [1217102780@qq.com]
 * @Module ID:   <(模块)类编号，可以引用系统设计中的类编号>
 * @Comments: <对此类的描述，可以引用系统设计中的描述>
 * @JDK version used:      <JDK1.8> 30
 * @since 2019/1/14-15:30
 */
public class ThreadLocalDemo {
    static Map<Thread, Integer> data = new HashMap<Thread, Integer>();

    public static void main(String[] args) {
        for (int i = 0; i < 3; i++) {
            new Thread(new Runnable() {
                public void run() {
                    int rom = new Random().nextInt();
                    data.put(Thread.currentThread(), rom);
                    System.out.println("放进 线程" + Thread.currentThread().getName()+"的数据:" + rom);

                    new A().get();
                    new B().get();
                }
            }).start();
        }
    }

    static class A {
        public void get() {
            int i = data.get(Thread.currentThread());
            System.out.println("A 拿到的数据：" +i);
        }
    }

    static class B {
        public void get() {
            int i = data.get(Thread.currentThread());
            System.out.println("B 拿到的数据：" +i);
        }
    }
}
